package br.com.jbssistemas.dirfweb.managedbeans;

import br.com.jbssistemas.dirfweb.entidades.Beneficiario;
import br.com.jbssistemas.dirfweb.hibernate.HibernateUtil;
import br.com.jbssistemas.dirfweb.util.ReportUtil;
import java.io.IOException;
import java.io.Serializable;
import java.sql.Connection;
import java.sql.SQLException;
import java.text.ParseException;
import java.util.HashMap;
import java.util.Locale;
import javax.inject.Named;
import javax.faces.view.ViewScoped;
import net.sf.jasperreports.engine.JRException;
import net.sf.jasperreports.engine.JasperRunManager;

/**
 *
 * @author Renato Machado
 *
 */
@Named(value = "dirfMB")
@ViewScoped
public class DirfItemMB implements Serializable {

    public DirfItemMB() {
    }

    public void visualizarDirf(Beneficiario beneficiario) throws ParseException, JRException, IOException, SQLException {
        ReportUtil reportUtil = new ReportUtil();
        HashMap parametros = new HashMap();
        parametros.put("paramBeneficiarioID", beneficiario.getId());
        /*parametros.put("IMAGEM", reportUtil.getJavaPath() + "/logos/logo_brejo_santo.png");*/
        parametros.put("REPORT_LOCALE", new Locale("pt", "BR"));
        /*parametros.put("SUBREPORT_DIR", reportUtil.getJavaPath() + "/");*/
        Connection connection = HibernateUtil.getConnection();
        byte[] pdfRelatorio = JasperRunManager.runReportToPdf(reportUtil.getJavaPath() + "/Dirf.jasper", parametros, connection);
        reportUtil.mostrarRelatorio(pdfRelatorio, reportUtil.getResponse());
    }

}
